
var url = require("url");
console.log(url);

/*
    url.parse(urlString,boolean)
    urlString  :  url地址
    第二个参数（可省）传入一个布尔值，默认为false，为true时，返回的url对象中，query的属性为一个对象。

*/

/* var str = "http://huaishuanglingzhi.com:8080/index.html?name=huaishuang&age=18#one"
var obj = url.parse(str);
console.log(obj);
var obj = url.parse(str, true);
console.log(obj);


var obj = {
    protocol: 'http:',
    hostname: 'huaishuanglingzhi.com',
    port: '8080',
    pathname: '/index.html',
    search: '?name=huaishuang&age=18',
    hash: '#one',
}

var str = url.format(obj); */
// console.log(str);


var URL = url.URL;

var str = "http://huaishuanglingzhi.com:8080/index.html?name=huaishuang&age=18#one"
var obj = new URL(str);
console.log(obj);

var searchParams = obj.searchParams;
console.log(searchParams);
// console.log(searchParams.name);  // 不能通过.语法取值
// console.log(searchParams.age);  //  不能通过.语法取值
// console.log(searchParams.__proto__);


// console.log(searchParams.get("name"));
// console.log(searchParams.get("age"));

// searchParams.set("name", "张飒");
// searchParams.set("age", "24");

// console.log(searchParams.has("name"));
// console.log(searchParams.has("age"));

// console.log(searchParams.delete("name"));
// console.log(searchParams.delete("age"));

// console.log(searchParams);

var list = [...searchParams];
console.log(list);

var obj = Object.fromEntries(list);
console.log(obj);